//
//  ContentView.swift 首页
//  swiftStudy
//
//  Created by Zhang on 2021/3/15.
//

import SwiftUI

struct ContentView: View {
    
    //基本语法item
    let language = [
        HomeListItem(title: "变量与常量", subTitle: "变量与常量"),
        
        HomeListItem(title: "基本数据类型", subTitle: "基本数据类型"),
        
        HomeListItem(title: "字符、字符串", subTitle: "字符、字符串"),
        
        HomeListItem(title: "集合", subTitle: "字符、字符串"),
    
        HomeListItem(title: "运算符", subTitle: "运算符"),
        
        HomeListItem(title: "函数基础", subTitle: "函数基础"),
        
        HomeListItem(title: "函数类型与嵌套", subTitle: "函数类型与嵌套"),
        
        HomeListItem(title: "枚举", subTitle: "枚举"),
        
        HomeListItem(title: "类与结构体", subTitle: "类与结构体"),
        
        HomeListItem(title: "属性", subTitle: "属性"),
        
        HomeListItem(title: "方法", subTitle: "方法"),
        
        HomeListItem(title: "构造方法和析构方法", subTitle: "构造方法和析构方法"),
        
        HomeListItem(title: "内存管理与异常处理", subTitle: "内存管理与异常处理"),
        
        HomeListItem(title: "类型转换、泛型、扩展与协议", subTitle: "类型转换、泛型、扩展与协议"),
    ]
    //控件使用
    let widgets = [
        HomeListItem(title: "文字",subTitle:"文本控件,用于展示文字"),
        
        HomeListItem(title: "按钮",subTitle: "按钮控件,用于展示按钮"),
        
        HomeListItem(title: "MapKit",subTitle: "展示地图"),
        
        HomeListItem(title: "List",subTitle: "展示列表"),
    ]

    //参考文档
    let reference = HomeListItem(title: "参考文档",subTitle:"参考的文档和开源项目")
    
    var body: some View {
       
        NavigationView{
          
            //表单控件
            Form{
                //使用Section添加一个标题
                Section(header:SectionHeaderView(title: "基础语法",isNeedTab: false)){
                    //使用ForEach创建View
                    ForEach(0..<language.count){index in
                        
                        //导航到destination指向的View
                        NavigationLink(destination: ControlView(itemInfo:language[index])){
                            
                            PageRow(title: language[index].title,
                                    subTitle: language[index].subTitle)
                            
                        }.padding(10)
                    }
                }
                
                //使用Section添加一个标题
                Section(header:SectionHeaderView(title: "基础控件",isNeedTab: false)){
                    //使用ForEach创建View
                    ForEach(0..<widgets.count){index in
                        
                        //导航到destination指向的View
                        NavigationLink(destination: ControlView(itemInfo: widgets[index])) {
                            PageRow(title: widgets[index].title,
                                    subTitle: widgets[index].subTitle)
                        }.padding(10)
                        
                        
                    }
                }
                
                //使用Section添加一个标题
                Section(header:SectionHeaderView(title: "参考",isNeedTab: false)){
                    //导航到destination指向的View
                    NavigationLink(destination: ControlView(itemInfo:reference)) {
                        PageRow(title:reference.title,
                                subTitle:reference.subTitle)
                    }.padding(10)
                }
                
            }
            .navigationBarTitle("首页",displayMode: .inline)
            
        }
        
    }
    
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
